package cn.gson.springboot.model.service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;

import cn.gson.springboot.model.dao.ClinicCardDAO;
import cn.gson.springboot.model.mapper.ClinicCardMapper;
import cn.gson.springboot.model.mapper.RechangeMapper;
import cn.gson.springboot.model.pojos.ClinicCard;

@Service
@Transactional(rollbackFor=Exception.class)
public class ClinicCardService {
	
	@Autowired
	private ClinicCardMapper ccmapper;
	
	@Autowired
	private ClinicCardDAO ccdao;
	
	@Autowired
	private RechangeMapper  remapper;
	
	//新增医疗卡
	public void addcliniccard( String cliniccardid,String clinicname,String clinicCard, Integer clinicage,
			 										 String clinic_sex, String clinic_tel,String clinic_address,
			 										 String clinic_handlename,BigDecimal clinic_remainmoney,Integer clinic_state){
		
       ccmapper.addcliniccard(cliniccardid, clinicname, clinicCard, clinicage, clinic_sex, clinic_tel, clinic_address, clinic_handlename, clinic_remainmoney,clinic_state);
	}
	
	//查询所有
	/*public List<ClinicCard> selectAllclinic(){
		return (List<ClinicCard>) ccdao.findAll();
	}*/
	
	//根据医疗卡查询或者查询所有
	public List<ClinicCard>  selectAllbycardid(Integer clinicstate,String cliniccardid,String clinicname,String clinic_idnumber) {
		return ccmapper.selectAllbycardid(clinicstate,cliniccardid,clinicname,clinic_idnumber);
	}
	
	//修改余额
	public void updatemoney(BigDecimal money,Integer clinicid) {
		ccmapper.updatemoney(money, clinicid);
	}
	
	public void updatejianmoney(BigDecimal money,Integer clinicid) {
		ccmapper.updatejianmoney(money, clinicid);
	}
	
	//看诊医疗卡搜索
	public JSONArray lookdoctorclinic(Integer regstrstate,String cliniccardid,Integer sectionid,Integer regstrid) {
		return ccmapper.lookdoctorclinic(regstrstate, cliniccardid,sectionid, regstrid);
	}
	
	//根据登录人用户id查对应科室id以便看诊出现对应病人
	public JSONArray selectLookDoctorBysid(String rolename,Integer userid) {
		return ccmapper.selectLookDoctorBysid(rolename, userid);
	}
	
	//叫号信息
	public JSONArray lookdoctorCall(Integer regstrcall,Integer regstrstate,String cliniccardid,
																	  Integer sectionid,Integer regstrid) {
		return ccmapper.lookdoctorCall(regstrcall, regstrstate, cliniccardid, sectionid, regstrid);
	}
	
	//收费查询
	public JSONArray chargemoneylookillnessid (Integer lookstate,Integer lookid) {
		 return ccmapper.chargemoneylookillnessid(lookstate, lookid);
	}
	
	//根据医疗卡id查询（用于住院自主 登记）
	public ClinicCard findByhospcradid(String cradid) {
		return ccdao.findByhospcradid(cradid);
	}

	//药物收费
	public JSONArray selectdrugMoney(Integer dmoneytype,Integer lookid) {
		return ccmapper.selectdrugMoney( dmoneytype,lookid);
	}
	
	//体检项目收费
	public JSONArray selecthealMoney(Integer lookid) {
		return ccmapper.selecthealMoney(lookid);
	}
	
	//自主体检人员信息
   public JSONArray selectselfhealthClinic() {
	   return ccmapper.selectselfhealthClinic();
   }
	
	//自主体检收费
   public JSONArray selectselfhealthmoney(String cid) {
	   return ccmapper.selectselfhealthmoney(cid);
   }
   
 //医疗项目收费
 	public JSONArray selectHosptialMoney(Integer llid) {
 		return ccmapper.selectHosptialMoney(llid);
 	}
 	
 	//住院申请
 	public JSONArray selectApplyhospital(Integer lid) {
 		return ccmapper.selectapplyhospital(lid);
 	}
 	
	/*根据挂号id查询看诊号*/
	public JSONArray selectByLookid(@Param("registr_id")Integer registr_id) {
		return ccmapper.selectByLookid(registr_id);
	}
	
	//病历本看诊记录
   public JSONArray selectBylookrecord(Integer cid,Date lookdate) {
	   return ccmapper.selectBylookrecord(cid,lookdate);
   }

   //病历本体检记录与结果
 	public JSONArray selectByhealthrecord(Integer cid, Date lookdate) {
 		return ccmapper.selectByhealthrecord(cid, lookdate);
 	};
 	
 	//查询当天挂号记录
 	public JSONArray selectByPresentRegistrPeople(){
 		return ccmapper.selectByPresentRegistrPeople();
 	}
}
